<?php


namespace app\miniapp\controller;


use app\common\controller\Api;
use app\miniapp\model\MemberModel;
use app\miniapp\validate\MemberValidate;

class Member extends Base
{
    protected $noNeedLogin = '*';
    //用户信息
    public function user()
    {
        $id = $this->userId;
        $user = MemberModel::field('id,name,image,mobile')->find($id);
        $this->success('查询成功',[
            'user' => $user
        ]);

    }
    //修改用户信息
    public function edit()
    {
        $data = input('post.');
        $validate = new MemberValidate();
        $res = $validate->scene('edit')->check($data);
        if (!$res) {
            $this->error($validate->getError());
        }
        $user = MemberModel::find($this->userId);
        if (!$user) {
            $this->error('没有该数据');
        }
        $user->name = $data['name'];
        $user->image = $data['image'];
        $user->mobile = $data['mobile'];
        if ($user->save()) {
            $this->success('修改成功');
        }else{
            $this->error('修改失败');
        }

    }

}